# -*- coding: utf-8 -*-
# @Time    : 2019/9/16 11:04
# @Author  : Weymouth
# @Email   : 261229090@qq.com
# @File    : shopping.py
# @Software: PyCharm
# ---------------------------------------------------

product_list = (
    ('Mac', 1000),
    ('kindle', 800),
    ('tesla', 290000),
    ('book', 3000),
    ('bike', 40000),
)

shopping_car=[]

saving = input('please input your money: ')
if saving.isdigit():
    saving = int(saving)
    while True:

        for i, v in enumerate(product_list, 1):
            print(i, '>>>', v)

        choice = input('选择购买商品编号[退出：q]：')
        if choice.isdigit():
            choice = int(choice)
            if choice>0 and choice<len(product_list):
                p_item = product_list[choice-1]
                if p_item[1]<saving:
                    saving-=p_item[1]
                    shopping_car.append(p_item)
                else:
                    print('余额不足,还剩%s'%saving)
                print(p_item)
            else:
                print('编码不存在')

        elif choice == 'q':
            print('----------您已经购买如下商品------------')
            for i in shopping_car:
                print(i)
            print('您还剩余额：%s元'%saving)
            break
        else:
            print('invalid input')
